package com.hjn.springcloud.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huaijn
 * @date 2021/12/23-16:58
 * @description todo
 */
@RestController
public class EurekaClientDiscoveryController {

  @Autowired
  EurekaDiscoveryClient client;

  @GetMapping("/client")
  public Object discovery(){
    List<String> services = client.getServices();
    System.out.println("services:"+services);
    List<ServiceInstance> instances = client.getInstances("SPRING-USER-MANAGER");
    for (ServiceInstance instance : instances) {
      System.out.println(instance.getHost());
      System.out.println(instance.getInstanceId());
      System.out.println(instance.getPort());
      System.out.println(instance.getScheme());
      System.out.println(instance.getUri());

    }
    return this.client;
  }
}
